//---------------------------------------------------------------------------
#pragma hdrstop
#include "LoanArticle.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
LoanArticle::LoanArticle()
{
	initialize1(0, "noname", 0, "unknown", 0.0, 0.0);
}
//---------------------------------------------------------------------------
LoanArticle::LoanArticle(int id1, AnsiString name1, int nrOfItems1, AnsiString kind1, double price1, double deposit1)
{
	initialize1(id1, name1, nrOfItems1, kind1, price1, deposit1);
}
//---------------------------------------------------------------------------
void LoanArticle::initialize1(int id1, AnsiString name1, int nrOfItems1, AnsiString kind1, double price1, double deposit1)
{
	this->articleID1 = id1;
	this->name1 = name1;
	this->nrOfItems1 = nrOfItems1;
	this->kind1 = kind1;
	this->price1 = price1;
	this->deposit1 = deposit1;
}
//---------------------------------------------------------------------------
int LoanArticle::getArticleID1()	  { return this->articleID1; }
//---------------------------------------------------------------------------
AnsiString LoanArticle::getName1() { return this->name1; }
//---------------------------------------------------------------------------
int LoanArticle::getNrOfItems1()   { return this->nrOfItems1; }
//---------------------------------------------------------------------------
AnsiString LoanArticle::getKind1() { return this->kind1; }
//---------------------------------------------------------------------------
double LoanArticle::getPrice1()    { return this->price1; }
//---------------------------------------------------------------------------
double LoanArticle::getDeposit1()    { return this->deposit1; }
//---------------------------------------------------------------------------
AnsiString LoanArticle::asAString1()
{
	AnsiString temp = padRight1(this->name1, 18);
	// check the stock of the article
	if (this->nrOfItems1 > 0)
	{
		temp += padRight1((AnsiString)this->nrOfItems1, 5)+padRight1(this->kind1, 10)
				+padRight1(AnsiString().FormatFloat("0.00", this->price1), 7);
		// check the desposit of the article
		if (this->deposit1 > 0) {
			temp += AnsiString().FormatFloat("0.00", this->deposit1);
		}
	}
	else
	{
		temp += "- OUT OF STOCK";
	}
	return temp;
}
//---------------------------------------------------------------------------
void LoanArticle::decreaseNrOfItemsBy1(int amount1)
{
	this->nrOfItems1 -= amount1;
}
//---------------------------------------------------------------------------
void LoanArticle::increaseNrOfItemsBy1(int amount1)
{
	this->nrOfItems1 += amount1;
}
//---------------------------------------------------------------------------
AnsiString LoanArticle::padRight1(AnsiString str1, int len1)
{
	if (str1.Length() < len1)
	{
		return str1+AnsiString().StringOfChar(' ', len1-str1.Length());
	}
	else
	{
		return str1+" ";
	}
}
//---------------------------------------------------------------------------
